package com.xiyi.shouxin.dao.user;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.xiyi.shouxin.dao.BaseRepository;
import com.xiyi.shouxin.dao.JdbcPreparedStatement;
import com.xiyi.shouxin.entity.user.Music;
import com.xiyi.shouxin.entity.user.mapper.MusicMapper;

@Repository
public class MusicRepository extends BaseRepository<Music> {
    public MusicRepository() {
        super();
        super.stat = new JdbcPreparedStatement<>(Music.class);
    }

    public List<Music> findByMultiConditionsByPage(String name, Sort sort, int page, int size)
            throws Exception {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (StringUtils.hasText(name)) {
            conditions.add(stat.GetColumnName("name") + " LIKE ? ");
            args.add("%" + name + "%");
        }
        return findByMultiConditionsByPage(conditions, args, sort, page, size, new MusicMapper());
    }

    public int countByMultiConditions(String name) {
        List<Object> args = new ArrayList<>();
        List<String> conditions = new ArrayList<>();
        if (StringUtils.hasText(name)) {
            conditions.add(stat.GetColumnName("name") + " LIKE ? ");
            args.add("%" + name + "%");
        }
        return countByMultiConditions(conditions, args);
    }
}
